package exam._3;

import java.io.*;

public class UserServiceImpl implements UserService {

    @Override
    public boolean register(User user) throws IOException {
        String s=user.name;
        File f1=new File("d:/s.txt");
        BufferedWriter bw=new BufferedWriter(new FileWriter(f1));
        bw.write("name:"+user.name+"\r\n");
        bw.write("username:"+user.username+"\r\n");
        bw.write("password:"+user.password+"\r\n");
        bw.close();

        return true;
    }

    @Override
    public boolean login(String username, String password) throws IOException {
        File f1=new File("d:/username.txt");
        BufferedReader br=new BufferedReader(new FileReader(f1));

        String line=br.readLine();

        String[] s=line.split("=");

        if (s[3]==username && s[5]==password){
            return true;
        }else{
            return false;
        }
    }

}
